package com.fly.lambda.framework.dao;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Fly on 2016/7/13.
 */
public class Pagination<T> {

    public Pagination(){}

    public Pagination(List elements, int totalRows, int pageNumber, int pageSize){
        this.elements = elements;
        this.totalRows = totalRows;
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
    }

    private List<T> elements = new ArrayList<T>();

    private int pageNumber =1;

    private int totalRows;

    private int pageSize=20;

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getElements() {
        return elements;
    }

    public void setElements(List<T> elements) {
        this.elements = elements;
    }

    public int getTotalPage(){
        if (totalRows == 0){
            return 0;
        }
        else {
            return totalRows % pageSize == 0 ? totalRows / pageSize : totalRows / pageSize + 1;
        }
    }

    public boolean hasPrePage(){
        return pageNumber > 1 && getTotalPage() > 1;
    }

    public boolean hasNextPage(){
        return pageNumber < getTotalPage();
    }
}
